﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;
using System.Text;

/// <summary>
/// Summary description for FileDownLoadComm
/// </summary>
public class FileDownLoadComm
{
	public FileDownLoadComm()
	{
		//
		// TODO: Add constructor logic here
		//
	}

    public void FileDownload(System.Web.UI.Page page, FileDownLoadModel model)
    {

        string pathL = page.Server.MapPath("~/" + model.FilePosition + model.ContractNoMain + model.SoNo + model.FileName);
        FileInfo fiL = new FileInfo(pathL);

        if (fiL.Exists)
        {
            page.Response.Clear();
            page.Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(model.FileName, Encoding.UTF8).ToString());
            page.Response.AddHeader("Content-Length", fiL.Length.ToString());
            page.Response.ContentType = "application/octec-stream;charset=gb2312";
            page.Response.Filter.Close();
            page.Response.WriteFile(fiL.FullName);
            page.Response.End();
        }
        else
        {
            CommonMethod.regAlertMessage(model.FileName + " Not exit ！！", page);
        }
    }
}